﻿using System;
using System.Collections.Generic;
using System.Linq;
using MoreExtentions;

namespace MoreExtentions
{
    public static partial class Linq
    {
        public static void AddDistinct<T>(this ICollection<T> source, params ICollection<T>[] collections)
        {
            (from collection in collections from item in collection where !source.Contains(item) select item).ForEach(source.Add);
        }

        public static void AddDistinct<T>(this ICollection<T> source, Func<T, bool> predicate, params ICollection<T>[] collections)
        {
            collections.ForEach(collection => collection.Where(predicate).Where(item => !source.Contains(item)).ForEach(source.Add));
        }

        public static void AddDistinct<T>(this ICollection<T> source, params T[] items)
        {
            items.Where(item => !source.Contains(item)).ForEach(source.Add);
        }

        public static void AddDistinct<T>(this ICollection<T> source, Func<T, bool> predicate, params T[] items)
        {
            items.Where(predicate).Where(x => !source.Contains(x)).ForEach(source.Add);
        }
    }
}